/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2017-07-21 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.pbpm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itttq.gshop.domain.po.OrderWarePo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.pbpm.mapper.IOrderWareMapper;

@Service
public class OrderWareService {
	@Autowired
	private IOrderWareMapper orderWareMapper;
	
	/**
	 * 根据订单ID查询此订单的所有商品信息
	 * 
	 * @param orderId	订单ID
	 * @Author 迷蝶
	 * @return List<OrderWarePo>
	 */
	public List<OrderWarePo> getOrderWareByOrderId(int orderId) {
		return orderWareMapper.findOrderWareByOrderId(orderId);
	}
	/**
	 * 根据订单ID集合查询此订单的所有商品信息
	 * 
	 * @param orderIds	订单ID集合
	 * @Author 迷蝶
	 * @return List<OrderWarePo>
	 */
	public List<OrderWarePo> getOrderWareByOrderIds(List<Integer> orderIds) {
		return orderWareMapper.findOrderWareByOrderIds(orderIds);
	}
	
	/**
	 * 根据ID获取OrderWarePo对象
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return OrderWarePo
	 */
	public OrderWarePo getOrderWare(int id) {
		return orderWareMapper.findOrderWareById(id);
	}
	
	/**
	 * 根据条件获取OrderWarePo对象，并返回查询的数据总数
	 * 
	 * @param orderWare
	 * @Author 迷蝶
	 * @return ResultPageTo<OrderWarePo>
	 */
	public ResultPageTo<OrderWarePo> getOrderWares(OrderWarePo orderWare) {
		return new ResultPageTo<OrderWarePo>(orderWare.getStart(), orderWare.getSize(), 
				orderWareMapper.findOrderWareCount(orderWare), orderWareMapper.findOrderWares(orderWare));
	}
	
	/**
	 * 根据ID删除OrderWarePo对象
	 * 
	 * @param id
	 * @Author 迷蝶
	 */
	public Integer delOrderWare(int id) {
		return orderWareMapper.delOrderWareById(id);
	}
	
	/**
	 * 增加OrderWarePo对象
	 * 
	 * @param orderWare
	 * @Author 迷蝶
	 */
	public Integer addOrderWare(OrderWarePo orderWare) {
		return orderWareMapper.addOrderWare(orderWare);
	}
	
	/**
	 * 根据条件更新OrderWarePo对象
	 * 
	 * @param orderWare
	 * @Author 迷蝶
	 */
	public Integer updateOrderWare(OrderWarePo orderWare) {
		return orderWareMapper.updateOrderWare(orderWare);
	}
	
	/**
	 * 批量增加订单商品
	 * 
	 * @param orderWares		订单商品对象集合
	 * @param orderId	订单ID
	 * @return
	 * @Author 迷蝶
	 * @return Integer
	 */
	public Integer addBatch(List<OrderWarePo> orderWares, int orderId) {
		for(OrderWarePo owp : orderWares) {
			owp.setOrderId(orderId);
		}
		Map<String, List<OrderWarePo>> map = new HashMap<String, List<OrderWarePo>>();
		map.put("orderWares", orderWares);
		return orderWareMapper.insertBatch(map);
	}
	
}
